home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 49 / Amiga Format CD49 (2000-01-17)(Future Publishing)(GB)(Track 1 of 3)[!][issue 2000-02].iso / -serious- / comms / other / cim_r32 / stuff / scripts / arexx / logsizer / logsizer.rexx next >
OS/2 REXX Batch file  |  1999-12-06  |  2KB  |  73 lines

  1. /*
  2. ** $VER: logsizer.rexx 1.2 (25.11.97) Rolf Rotvel
  3. */
  4.  
  5. cfgfile = 'logsizer.cfg'
  6.  
  7. /*
  8. ** End cfg.
  9. */
  10. call addlib('rexxsupport.library', 0, -30, 0)
  11.  
  12. if ~open('cfg', cfgfile, 'r') then do
  13.     say 'Error reading '||cfgfile
  14.     exit 10
  15. end
  16.  
  17. nl = '0a'x
  18. nl2 = nl||nl
  19. maxstr = 65535
  20.  
  21. do forever
  22.     parse value readln('cfg') with log kb .
  23.     if log = '' then leave
  24.  
  25.     info = statef(log)
  26.     filesize = word(info, 2)
  27.  
  28.     select
  29.         when ~datatype(kb, 'w') then do
  30.             say 'New size = 'kb' kb ?!?'
  31.         end
  32.         when kb < 1 then do
  33.             say 'New size = 'kb' kb ?!?'
  34.         end
  35.         when info = '' then do
  36.             say 'Logfile 'log' doesn''t exist'
  37.         end
  38.         when filesize = 0 then do
  39.             say 'Logfile 'log' is empty (0 bytes)'
  40.         end
  41.         otherwise do
  42.             checksize = kb * 1024
  43.         
  44.             if filesize > checksize then do
  45.                 say 'Resizing '||log||' ('||filesize||' > '||checksize||')'
  46.                 start = filesize - checksize
  47.             
  48.                 newlog.0 = (checksize % maxstr) + 1      
  49.  
  50.                 call open('tmp', log, 'r')
  51.                 call seek('tmp', start)
  52.                 do n = 1 to newlog.0
  53.                     newlog.n = readch('tmp', maxstr)
  54.                 end
  55.                 call close('tmp')
  56.  
  57.                 if pos(nl2, newlog.1) > 0 then parse var newlog.1 . (nl2) newlog.1
  58.                 else parse var newlog.1 . (nl) newlog.1
  59.  
  60.                 call open('tmp', log, 'w')
  61.                 do n = 1 to newlog.0
  62.                     call writech('tmp', newlog.n)
  63.                 end
  64.                 call close('tmp')
  65.             end
  66.             else say 'Skipping '||log||' ('||filesize||' <= '||checksize||')'
  67.         end
  68.     end
  69. end
  70.  
  71. call close('cfg')
  72. exit
  73.